﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ARR.Entities;
using System.Collections.ObjectModel;
using ARR.UI.AuditTrailsService;

namespace ARR.UI.Models
{
    public interface IInventoriesImporterModel : IModelBase
    {
        List<ImporterResult> Results { get; set; }

        void SaveAuditTrails(List<AuditTrail> auditTrails);

        ObservableCollection<TempInventory> TempInventories { get; set; }

        ObservableCollection<TempInventory> TempInventoriesCache { get; set; }
    }

    public class InventoriesImporterModel : ModelBase, IInventoriesImporterModel
    {
        public InventoriesImporterModel()
        {
            this.Results = new List<ImporterResult>();
            this.TempInventories = new ObservableCollection<TempInventory>();
            this.TempInventoriesCache = new ObservableCollection<TempInventory>();
        }

        public List<ImporterResult> Results { get; set; }

        public ObservableCollection<TempInventory> TempInventories { get; set; }

        public ObservableCollection<TempInventory> TempInventoriesCache { get; set; }

        public void SaveAuditTrails(List<AuditTrail> auditTrails)
        {
            AuditTrailsServiceClient service = new AuditTrailsServiceClient();

            try
            {
                service.SaveAuditTrails(auditTrails);
                service.Close();
            }
            catch
            {
                service.Abort();
                throw;
            }
        }
    }


    public class InventoriesImporterModelMock : MockModelBase, IInventoriesImporterModel
    {
        public InventoriesImporterModelMock()
        {
            this.Results = new List<ImporterResult>();
            this.TempInventories = new ObservableCollection<TempInventory>();
            this.TempInventoriesCache = new ObservableCollection<TempInventory>();
        }

        public List<ImporterResult> Results { get; set; }

        public ObservableCollection<TempInventory> TempInventories { get; set; }

        public ObservableCollection<TempInventory> TempInventoriesCache { get; set; }

        public void SaveAuditTrails(List<AuditTrail> auditTrails)
        {
        }
    }
}
